using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint.WebControls;
using System.Web.UI.WebControls;
using Microsoft.SharePoint;

namespace CKS.EBE.WebControls
{
    public class SearchBox : SPControl
    {
        protected TextBox _seachBox;
        protected Button _goButton;

        protected override void OnInit(EventArgs e)
        {
            EnsureChildControls();
            base.OnInit(e);
        }

        protected override void CreateChildControls()
        {
            string sFeed = RssFeed.GetFeed();

            _seachBox = new TextBox();
            _seachBox.ID = "idSearchBox";
            Controls.Add(_seachBox);

            Button _goButton = new Button();
            Controls.Add(_goButton);

            _goButton.Text = "Go";
            _goButton.ID = "idGoButton";
            _goButton.Click += new EventHandler(go_Click);
        }

        void go_Click(object sender, EventArgs e)
        {
            if (_seachBox == null || _seachBox.Text == "") return;

            string sUrl = SPContext.Current.Web.Url;
            if (!sUrl.EndsWith("/")) sUrl += "/";

            Page.Response.Redirect(sUrl + "search.aspx?k=" + _seachBox.Text);
        }
    }
}
